package table.node;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

public class BaseNode implements DataNode {
	private Object nodeValue = null;
	private List<DataNode> subNodes = null;
	private String struct = "text";
	public BaseNode(){
		this.subNodes = new ArrayList<DataNode>();
	}
	public DataNode setNodeValue(Object nodeValue) {
		this.nodeValue = nodeValue;
		return this;
	}
	public Object getNodeValue() {
		return nodeValue;
	}
	public void setSubNodes(List<DataNode> subNodes) {
		this.subNodes = subNodes;
	}
	public List<DataNode> getSubNodes() {
		return subNodes;
	}
	public void setStruct(String struct) {
		this.struct = struct;
	}
	public String getStruct() {
		return struct;
	}
	public String traveler() {
		String result = "";
		try{
			TravelerListener.action(this.getNodeValue());
			if(this.getNodeValue() != null){
				result = this.getNodeValue().toString();
			}
			
			if(this.subNodes != null && this.subNodes.size() > 0){
				result += "<ul class='col'>";
				for(int i=0; i < this.subNodes.size(); i++){
					result += "<li>" + this.subNodes.get(i).traveler() + "</li>";
				}
				result += "</ul>";
			}
		}catch(Exception e){
		}
		return result;
	}
	public Object run(HttpServletRequest request){
		return null;
	}
	public String toString(){
		return this.traveler();
	}
}
